package xyz.zhouzhaodong.crm.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.zhouzhaodong.crm.dto.StaffDto;
import xyz.zhouzhaodong.crm.entity.Staff;
import xyz.zhouzhaodong.crm.service.StaffService;
import xyz.zhouzhaodong.crm.util.NoRepeatSubmit;
import xyz.zhouzhaodong.crm.util.RestMessage;

import javax.annotation.Resource;

/**
 * 登陆操作
 *
 * @author zhouzhaodong
 */
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Resource
    StaffService staffService;

    /**
     * 登录
     *
     * @param userName
     * @param password
     * @return
     */
    @RequestMapping("/login")
    public RestMessage login(String userName, String password) {
        return staffService.login(userName, password);
    }

    /**
     * 注册
     *
     * @param userName
     * @param password
     * @return
     */
    @RequestMapping("/register")
    public RestMessage register(String userName, String password) {
        return staffService.register(userName, password);
    }

    /**
     * 修改密码
     *
     * @param id
     * @param passwordOld
     * @param passwordNew
     * @return
     */
    @RequestMapping("/changePassword")
    public RestMessage changePassword(String id, String passwordOld, String passwordNew) {
        return staffService.changePassword(id, passwordOld, passwordNew);
    }

    /**
     * 更新员工信息
     *
     * @param staff
     * @return
     */
    @RequestMapping("/update")
    public RestMessage updateStaff(Staff staff) {
        return staffService.updateStaff(staff);
    }

    /**
     * 逻辑删除
     *
     * @param id
     * @param staffId
     * @return
     */
    @RequestMapping("/delete")
    public RestMessage deleteStaff(String id, String staffId) {
        return staffService.deleteStaff(id, staffId);
    }

    /**
     * 根据id查询用户信息
     *
     * @param id
     * @return
     */
    @RequestMapping("/select")
    public RestMessage selectStaff(String id) {
        return staffService.selectOne(id);
    }

    /**
     * 按照条件查询用户列表
     *
     * @param staffDto
     * @return
     */
    @RequestMapping("/selectList")
    public RestMessage selectStaffList(StaffDto staffDto) {
        return staffService.selectStaffList(staffDto);
    }

    /**
     * 管理员新增用户
     * @param staffDto
     * @return
     */
    @NoRepeatSubmit
    @RequestMapping("/addStaff")
    public RestMessage addStaff(StaffDto staffDto){
        return staffService.addStaff(staffDto);
    }

    /**
     * 管理员重置密码
     * @param staffDto
     * @return
     */
    @RequestMapping("/resetPasswrod")
    public RestMessage resetPasswrod(StaffDto staffDto){
        return staffService.resetPasswrod(staffDto);
    }

    /**
     * 管理员修改员工岗位
     * @param id
     * @param staffId
     * @param stationId
     * @return
     */
    @RequestMapping("/restStation")
    public RestMessage restStation(String id, String staffId, String stationId){
        return staffService.restStation(id, staffId, stationId);
    }

}
